import 'package:after_sale_plugin/r.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:lx_widgets_library/enum/order_state_enum.dart';
import 'package:lx_widgets_library/extension/lx_colors.dart';
import 'package:lx_widgets_library/language/language_util.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';
import 'package:lx_widgets_library/r.dart';
import 'package:lx_widgets_library/view/common_widget.dart';

import 'controller.dart';

class OrderHistoryListView extends BaseGetView<OrderHistoryListController> {
  @override
  String get title => AppLanguageUtil.to.titleOrderHistory;

  @override
  Color? get barBackgroundColor => Colors.black;

  @override
  Widget? get backView => CommonWidgets.appBarLeading();

  @override
  Widget buildBody(BuildContext context) {
    return Obx(
      () => Scaffold(
        backgroundColor: Colors.black,
        resizeToAvoidBottomInset: false,
        body: Visibility(
          replacement: CommonWidgets.emptyView(LxR.empty_png, title),
          visible: controller.state.orderInfoList.isNotEmpty,
          child: ListView.separated(
            controller: controller.scrollController,
            itemCount: controller.state.orderInfoList.length,
            itemBuilder: (BuildContext context, int index) {
              var model = controller.state.orderInfoList[index];
              return Padding(
                padding: EdgeInsets.all(CONTENT_MARGIN),
                child: ClipRRect(
                  borderRadius: const BorderRadius.all(Radius.circular(8)),
                  child: Container(
                    padding: EdgeInsets.all(CONTENT_MARGIN),
                    color: const Color(0xFF141414),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            LxText(
                              model.submitedDate,
                              fontWeightEnum: LxFontWeightEnum.bodyMedium,
                              color: Colors.white.withOpacity(0.6),
                            ),
                            InkWell(
                              onTap: () {
                                // 订单历史详情
                                controller.hisotyDetail(index);
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  LxText(
                                    model.orderProgressState.value.title,
                                    color: model.orderProgressState.value ==
                                            OrderProgressState.closed
                                        ? Colors.white.withOpacity(0.6)
                                        : LxColors.theme,
                                    fontWeightEnum: LxFontWeightEnum.bodySmall,
                                  ),
                                  const SizedBox(width: 3),
                                  Image.asset(
                                    R.item_arrow_png,
                                    package: PACKAGE_NAME,
                                    width: 20,
                                    fit: BoxFit.fitWidth,
                                  ),
                                ],
                              ),
                            )
                          ],
                        ),
                        SizedBox(height: CONTENT_MARGIN),
                        LxText(
                          model.problemContent.value,
                          fontWeightEnum: LxFontWeightEnum.bodyLarge,
                          color: Colors.white,
                        ),
                      ],
                    ),
                  ),
                ),
              );
            },
            separatorBuilder: (BuildContext context, int index) {
              return const Divider(
                color: Colors.transparent,
                height: 0,
                indent: 20,
              );
            },
          ),
        ),
      ),
    );
  }
}
